Completed
Push — master ( 6b1fd1...a60ffc )
by Rain
03:51
created

AbstractSystemDropDown.js ➔ ... ➔ ???   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 1
rs 10
c 0
b 0
f 0
1
2
import _ from '_';
3
import ko from 'ko';
4
import key from 'key';
5
6
import AppStore from 'Stores/User/App';
7
import AccountStore from 'Stores/User/Account';
8
import MessageStore from 'Stores/User/Message';
9
10
import {Capa, Magics, KeyState} from 'Common/Enums';
11
import {trim, isUnd} from 'Common/Utils';
12
import {settings} from 'Common/Links';
13
14
import * as Events from 'Common/Events';
15
import * as Settings from 'Storage/Settings';
16
17
import {getApp} from 'Helper/Apps/User';
18
19
import {showScreenPopup, setHash} from 'Knoin/Knoin';
20
import {AbstractViewNext} from 'Knoin/AbstractViewNext';
21
22
class AbstractSystemDropDownUserView extends AbstractViewNext
23
{
24
	constructor() {
25
		super();
26
27
		this.logoImg = trim(Settings.settingsGet('UserLogo'));
28
		this.logoTitle = trim(Settings.settingsGet('UserLogoTitle'));
29
30
		this.mobile = !!Settings.appSettingsGet('mobile');
31
		this.mobileDevice = !!Settings.appSettingsGet('mobileDevice');
32
33
		this.allowSettings = !!Settings.capa(Capa.Settings);
34
		this.allowHelp = !!Settings.capa(Capa.Help);
35
36
		this.currentAudio = AppStore.currentAudio;
37
38
		this.accountEmail = AccountStore.email;
39
40
		this.accounts = AccountStore.accounts;
41
		this.accountsUnreadCount = AccountStore.accountsUnreadCount;
42
43
		this.accountMenuDropdownTrigger = ko.observable(false);
44
		this.capaAdditionalAccounts = ko.observable(Settings.capa(Capa.AdditionalAccounts));
45
46
		this.addAccountClick = _.bind(this.addAccountClick, this);
47
48
		Events.sub('audio.stop', () => AppStore.currentAudio(''));
49
		Events.sub('audio.start', (sName) => AppStore.currentAudio(sName));
50
	}
51
52
	stopPlay() {
53
		Events.pub('audio.api.stop');
54
	}
55
56
	accountClick(oAccount, oEvent) {
57
		if (oAccount && oEvent && !isUnd(oEvent.which) && 1 === oEvent.which)
58
		{
59
			AccountStore.accounts.loading(true);
60
			_.delay(() => AccountStore.accounts.loading(false), Magics.Time1s);
61
		}
62
63
		return true;
64
	}
65
66
	emailTitle() {
67
		return AccountStore.email();
68
	}
69
70
	settingsClick() {
71
		if (Settings.capa(Capa.Settings))
72
		{
73
			setHash(settings());
74
		}
75
	}
76
77
	settingsHelp()
78
	{
79
		if (Settings.capa(Capa.Help))
80
		{
81
			showScreenPopup(require('View/Popup/KeyboardShortcutsHelp'));
82
		}
83
	}
84
85
	addAccountClick() {
86
		if (this.capaAdditionalAccounts())
87
		{
88
			showScreenPopup(require('View/Popup/Account'));
89
		}
90
	}
91
92
	logoutClick() {
93
		getApp().logout();
94
	}
95
96
	onBuild() {
97
		key('`', [KeyState.MessageList, KeyState.MessageView, KeyState.Settings], () => {
98
			if (this.viewModelVisibility())
99
			{
100
				MessageStore.messageFullScreenMode(false);
101
				this.accountMenuDropdownTrigger(true);
102
			}
103
		});
104
105
		// shortcuts help
106
		key('shift+/', [KeyState.MessageList, KeyState.MessageView, KeyState.Settings], () => {
107
			if (this.viewModelVisibility())
108
			{
109
				showScreenPopup(require('View/Popup/KeyboardShortcutsHelp'));
110
				return false;
111
			}
112
			return true;
113
		});
114
	}
115
}
116
117
export {AbstractSystemDropDownUserView, AbstractSystemDropDownUserView as default};
118